// pages/home/follow/more/more.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        brandList:{},//品牌的索引列表
    },

    /**
     * 生命周期函数--监听页面加载
     */
    doNothing(){},
onLoad: function (options) {
        this.getCarBrandList();
    },
    getCarBrandList(){
        if(null == app.globalData.carBrandList){
            app.sHttp.carBrandList().then(res =>{
                let brandList = {};
                res.brandList.forEach(item =>{
                    if(undefined == brandList[item.firstLetter]){
                        brandList[item.firstLetter] = [item]
                    }else{
                        brandList[item.firstLetter].push(item);
                    }
                });
                app.globalData.carBrandList = brandList;
                this.setData({
                    'brandList': brandList
                });
            },err=>{
                app.error(err.msg);
            })
        }else{
            this.setData({
                'brandList': app.globalData.carBrandList
            });
        }
      },
      // 回调回来的.加入关注
      brandClick(e){
          // 回调回来查看是否处于编辑状态.打开编辑状态.
          // 加入关注列表
          let chooseBrand = e.detail;
          app.sHttp.carBrandAttention({'operateType':1,'brandId':chooseBrand.brandId}).then(res =>{
            app.alert('关注成功');
            setTimeout(() => {
                app.BackPage();
            }, 500);
          },err=>{
            app.error(err.msg);
          });
      },

})